package com.hbnu.system.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hbnu.system.config.BaseException;
import com.hbnu.system.core.util.PageUtil;
import com.hbnu.system.mapper.IdentifyMapper;
import com.hbnu.system.model.dto.CheckBackDTO;
import com.hbnu.system.model.dto.IdentifyAddDTO;
import com.hbnu.system.model.dto.SearchPageDTO;
import com.hbnu.system.model.dto.UserDTO;
import com.hbnu.system.model.entity.Dept;
import com.hbnu.system.model.entity.Identify;
import com.hbnu.system.model.entity.User;
import com.hbnu.system.service.IDeptService;
import com.hbnu.system.service.IIdentifyService;
import com.hbnu.system.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2023-05-16
 */
@Service
public class IdentifyServiceImpl extends ServiceImpl<IdentifyMapper, Identify> implements IIdentifyService {

    @Autowired private IIdentifyService iIdentifyService;

    @Autowired private IUserService iUserService;

    @Autowired private IDeptService iDeptService;

    @Override
    public boolean addIdentify(IdentifyAddDTO identifyAddDTO) {
        if(StrUtil.isEmpty(identifyAddDTO.getIdentifyDept()) || StrUtil.isBlank(identifyAddDTO.getIdentifyDept())){
            throw new BaseException("请输入鉴定部门");
        }
        if(StrUtil.isEmpty(identifyAddDTO.getIdentifyNum()) || StrUtil.isBlank(identifyAddDTO.getIdentifyNum())){
            throw new BaseException("请输入鉴定号");
        }
        if(StrUtil.isEmpty(identifyAddDTO.getIdentifyLevel()) || StrUtil.isBlank(identifyAddDTO.getIdentifyLevel())){
            throw new BaseException("请输入鉴定级别");
        }
        if(StrUtil.isEmpty(identifyAddDTO.getIdentifyResult()) || StrUtil.isBlank(identifyAddDTO.getIdentifyResult())){
            throw new BaseException("请输入鉴定结论");
        }
        if(StrUtil.isEmpty(identifyAddDTO.getAchievementName()) || StrUtil.isBlank(identifyAddDTO.getAchievementName())){
            throw new BaseException("请输入成果名称");
        }

        Identify one = super.getOne(Wrappers.lambdaQuery(Identify.class)
                .eq(Identify::getAchievementName, identifyAddDTO.getAchievementName()));
        if(Objects.nonNull(one)){
            throw new BaseException("改成果名称已被使用!");
        }

        Identify identify = new Identify();
        identify.setIdentifyNum(identifyAddDTO.getIdentifyNum());
        identify.setIdentifyDept(identifyAddDTO.getIdentifyDept());
        identify.setIdentifyLevel(identifyAddDTO.getIdentifyLevel());
        identify.setIdentifyResult(identifyAddDTO.getIdentifyResult());
        identify.setAchievementName(identifyAddDTO.getAchievementName());

        //检查各项不可为空选项
        identify.setClassifi("");
        identify.setOrganization("");
        identify.setCertificateID("");
        identify.setCompletionForm("");
        identify.setDiscipline("");
        identify.setStatus("草稿");
        identify.setSchoolSigned("");
        identify.setNotes("");
        identify.setEntered("");
        identify.setAllAuthor("");
        identify.setAssociatedProjects("");
//        identify.setEnteredDate(LocalDateTime.now());
////      paper.setDept(iUserService.getOne(Wrappers.lambdaQuery(User.class).eq(User::getName,paper.getEntered())).getDept());
//        String dept = iUserService.getOne(Wrappers.lambdaQuery(User.class).eq(User::getName, paper.getEntered())).getDept();
//        String deptName = iDeptService.getById(dept).getDeptName();
//        identify.setDept(deptName);
        return baseMapper.insert(identify) == 1;
    }

    @Override
    public boolean addIdentify(Identify identify) {
        if(StrUtil.isBlank(identify.getClassifi()) || StrUtil.isEmpty(identify.getClassifi())){
            throw new BaseException("请输入统计分类");
        }
        if(StrUtil.isBlank(identify.getOrganization()) || StrUtil.isEmpty(identify.getOrganization())){
            throw new BaseException("请输入所属机构");
        }
        if(StrUtil.isBlank(identify.getCertificateID()) || StrUtil.isEmpty(identify.getCertificateID())){
            throw new BaseException("请输入科技成果登记证书号");
        }
        if(StrUtil.isBlank(identify.getCompletionForm()) || StrUtil.isEmpty(identify.getCompletionForm())){
            throw new BaseException("请输入完成形式");
        }
        if(StrUtil.isBlank(identify.getDiscipline()) || StrUtil.isEmpty(identify.getDiscipline())){
            throw new BaseException("请输入学科门类");
        }
        if(StrUtil.isBlank(identify.getSchoolSigned()) || StrUtil.isEmpty(identify.getSchoolSigned())){
            throw new BaseException("请输入学校署名");
        }
        if(StrUtil.isBlank(identify.getEntered()) ||StrUtil.isBlank(identify.getEntered())){
            throw new BaseException("请输入录入人");
        }
        Identify one1 = super.getOne(Wrappers.lambdaQuery(Identify.class)
                .eq(Identify::getAchievementName, identify.getAchievementName()));
        if(Objects.nonNull(one1) && !(one1.getIdentifyID().equals(identify.getIdentifyID()))){
            throw new BaseException("成果名称重复!");
        }
        identify.setStatus("草稿");
        if(Objects.isNull(identify.getEnteredDate())) {
            identify.setEnteredDate(LocalDate.now());
        }
        String dept = iUserService.getOne(Wrappers.lambdaQuery(User.class).eq(User::getName, identify.getEntered())).getDept();
        String deptName = iDeptService.getById(dept).getDeptName();
        identify.setDept(deptName);
        return baseMapper.insert(identify) == 1;

    }

    @Override
    public boolean deleteIdentify(String identifyID) {
        Identify one = super.getOne(Wrappers.lambdaQuery(Identify.class)
                .eq(Identify::getIdentifyID, identifyID));
        if (Objects.isNull(one)){
            throw new BaseException("成果鉴定编号有误!");
        }
        return baseMapper.deleteById(identifyID) == 1;
    }

    @Override
    public boolean updateIdentify(Identify identify) {
        if(StrUtil.isBlank(identify.getClassifi()) || StrUtil.isEmpty(identify.getClassifi())){
            throw new BaseException("请输入统计分类");
        }
        if(StrUtil.isBlank(identify.getOrganization()) || StrUtil.isEmpty(identify.getOrganization())){
            throw new BaseException("请输入所属机构");
        }
        if(StrUtil.isBlank(identify.getCertificateID()) || StrUtil.isEmpty(identify.getCertificateID())){
            throw new BaseException("请输入科技成果登记证书号");
        }
        if(StrUtil.isBlank(identify.getCompletionForm()) || StrUtil.isEmpty(identify.getCompletionForm())){
            throw new BaseException("请输入完成形式");
        }
        if(StrUtil.isBlank(identify.getDiscipline()) || StrUtil.isEmpty(identify.getDiscipline())){
            throw new BaseException("请输入学科门类");
        }
        if(StrUtil.isBlank(identify.getSchoolSigned()) || StrUtil.isEmpty(identify.getSchoolSigned())){
            throw new BaseException("请输入学校署名");
        }
        Identify one1 = super.getOne(Wrappers.lambdaQuery(Identify.class)
                .eq(Identify::getAchievementName, identify.getAchievementName()));
        if(Objects.nonNull(one1) && !(one1.getIdentifyID().equals(identify.getIdentifyID()))){
            throw new BaseException("成果名称重复!");
        }
        if(StrUtil.isEmpty(identify.getStatus()) || StrUtil.isBlank(identify.getStatus())){
            identify.setStatus(one1.getStatus());
        }
        return baseMapper.updateById(identify) == 1;
    }

    @Override
    public Identify getIdentify(String identifyID) {
        Identify identify = super.getOne(Wrappers.lambdaQuery(Identify.class)
                .eq(Identify::getIdentifyID, identifyID));
        if(Objects.isNull(identify)){
            throw new BaseException("成果鉴定编号异常!未查找到该成果鉴定");
        }
        return identify;
    }

    @Override
    public boolean checkIdentifyName(String achievementName) {
        Identify one = super.getOne(Wrappers.lambdaQuery(Identify.class)
                .eq(Identify::getAchievementName, achievementName));
        return (Objects.isNull(one));
    }

    @Override
    public IPage<Identify> pageCondition(SearchPageDTO searchPageDTO) {
        IPage<Identify> page = PageUtil.getPage(searchPageDTO.getPageNum(), searchPageDTO.getPageSize());
        LambdaQueryWrapper<Identify> wrapper = Wrappers.lambdaQuery(Identify.class);

        IPage<Identify> identifyIPage = baseMapper.selectPage(page, wrapper);
//        IPage<PaperVO> taskVOIPage = iBeanService.copyPageProperties(paperIPage, PaperVO.class);
        List<Identify> records = identifyIPage.getRecords();
        List<Identify> IdentifyS = new ArrayList<>();

        int count = 1;
        int start = searchPageDTO.getPageSize() * (searchPageDTO.getPageNum()-1)+1;
        int end = searchPageDTO.getPageNum() * searchPageDTO.getPageSize();
//        records.forEach(record->{
//            if (count >= start && count <= end){
//                PaperS.add(this.getPaper(record.getPaperID()));
//            }
//        });
        Collections.reverse(records);
        for (Identify record:records) {
            if (count >= start && count <= end){
                IdentifyS.add(this.getIdentify(record.getIdentifyID()));
            }
            count += 1;
        }


//        Collections.reverse(IdentifyS);
        identifyIPage.setRecords(IdentifyS);
        identifyIPage.setTotal(IdentifyS.size());
        return identifyIPage;
    }

    @Override
    public Boolean collegeCheckPass(String PID) {
        Identify identify = iIdentifyService.getIdentify(PID);
        if (Objects.isNull(identify)){
            throw new BaseException("该成果鉴定编号有误!");
        }
        if(!identify.getStatus().equals("待院级审核")){
            throw new BaseException("该成果鉴定状态不处于该环节!");
        }
        identify.setStatus("待校级审核");
        return baseMapper.updateById(identify) == 1;
    }

    @Override
    public Boolean collegeCheckBack(CheckBackDTO checkBackDTO) {
        String id = checkBackDTO.getID();
        Identify identify = iIdentifyService.getIdentify(id);
        if (Objects.isNull(identify)){
            throw new BaseException("该成果鉴定编号有误!");
        }
        if(!identify.getStatus().equals("待院级审核")){
            throw new BaseException("该成果鉴定状态不处于该环节!");
        }
        identify.setStatus("被院级退回");
        identify.setReason(checkBackDTO.getReason());
        return baseMapper.updateById(identify) == 1;
    }

    @Override
    public Boolean schoolCheckPass(String IdentifyID) {
        Identify identify = iIdentifyService.getIdentify(IdentifyID);
        if (Objects.isNull(identify)){
            throw new BaseException("该鉴定编号有误!");
        }
        if(!identify.getStatus().equals("待校级审核")){
            throw new BaseException("该成果鉴定状态不处于该环节!");
        }
        identify.setStatus("审核通过");
        return baseMapper.updateById(identify) == 1;
    }

    @Override
    public Boolean schoolCheckBack(CheckBackDTO checkBackDTO) {
        String id = checkBackDTO.getID();
        Identify identify = iIdentifyService.getIdentify(id);
        if (Objects.isNull(identify)){
            throw new BaseException("该成果鉴定编号有误!");
        }
        if(!identify.getStatus().equals("待校级审核")){
            throw new BaseException("该成果鉴定状态不处于该环节!");
        }
        identify.setStatus("被校级退回");
        identify.setReason(checkBackDTO.getReason());
        return baseMapper.updateById(identify) == 1;
    }

    @Override
    public Boolean CommitIdentify(String IdentifyID) {
        Identify identify = super.getOne(Wrappers.lambdaQuery(Identify.class)
                .eq(Identify::getIdentifyID, IdentifyID));

        if(Objects.isNull(identify)){
            throw new BaseException("成果鉴定编号有误!");
        }
        if(!identify.getStatus().equals("草稿") && !identify.getStatus().equals("被校级退回")){
            throw new BaseException("该成果鉴定不适用于该阶段!");
        }

        if(StrUtil.isBlank(identify.getClassifi()) || StrUtil.isEmpty(identify.getClassifi())){
            throw new BaseException("统计分类信息不全");
        }
        if(StrUtil.isBlank(identify.getOrganization()) || StrUtil.isEmpty(identify.getOrganization())){
            throw new BaseException("所属机构信息不全");
        }
        if(StrUtil.isBlank(identify.getCertificateID()) || StrUtil.isEmpty(identify.getCertificateID())){
            throw new BaseException("科技成果登记证书号信息不全");
        }
        if(StrUtil.isBlank(identify.getCompletionForm()) || StrUtil.isEmpty(identify.getCompletionForm())){
            throw new BaseException("完成形式信息不全");
        }
        if(StrUtil.isBlank(identify.getDiscipline()) || StrUtil.isEmpty(identify.getDiscipline())){
            throw new BaseException("信息不全");
        }
        if(StrUtil.isBlank(identify.getSchoolSigned()) || StrUtil.isEmpty(identify.getSchoolSigned())){
            throw new BaseException("学校署名信息不全");
        }
        Identify one1 = super.getOne(Wrappers.lambdaQuery(Identify.class)
                .eq(Identify::getAchievementName, identify.getAchievementName()));
        if(Objects.nonNull(one1) && !(one1.getIdentifyID().equals(identify.getIdentifyID()))){
            throw new BaseException("成果名称重复!");
        }
        identify.setStatus("待校级审核");

        return baseMapper.updateById(identify) == 1;
    }

    @Override
    public IPage<Identify> userGetRelateIdentify(UserDTO userDTO) {
        User user = iUserService.getOne(Wrappers.lambdaQuery(User.class)
                .eq(User::getName, userDTO.getName()));
        if(Objects.isNull(user)){
            throw new BaseException("用户姓名有误!");
        }
        IPage<Identify> page = PageUtil.getPage(userDTO.getPageNum(), userDTO.getPageSize());

        LambdaQueryWrapper<Identify> wrapper = new LambdaQueryWrapper<>();
        if(user.getRole().equals("19177623324")){//判断身份如果是普通用户的话
            if(StrUtil.isBlank(userDTO.getState()) || StrUtil.isEmpty(userDTO.getState())){
                wrapper = Wrappers.lambdaQuery(Identify.class)
                        .eq(Identify::getEntered, userDTO.getName())
                        .or().eq(Identify::getLeadAuthor, userDTO.getName())
                        .or().eq(Identify::getCorrespondingAuthor,userDTO.getName())
                        .or().like(Identify::getAllAuthor,userDTO.getName());
            }else {
                wrapper = Wrappers.lambdaQuery(Identify.class)
                        .eq(Identify::getStatus,userDTO.getState())
                        .eq(Identify::getEntered, userDTO.getName())
                        .or().eq(Identify::getLeadAuthor, userDTO.getName())
                        .or().eq(Identify::getCorrespondingAuthor,userDTO.getName())
                        .or().like(Identify::getAllAuthor,userDTO.getName());
            }

        }else if (user.getRole().equals("19185212210")){ // 如果是院级管理员 给他看本院的
            if(StrUtil.isBlank(userDTO.getState()) || StrUtil.isEmpty(userDTO.getState())){
                Dept dept = iDeptService.getById(user.getDept());
                wrapper = Wrappers.lambdaQuery(Identify.class)
                        .eq(Identify::getDept,dept.getDeptName());
            }else {
                Dept dept = iDeptService.getById(user.getDept());
                wrapper = Wrappers.lambdaQuery(Identify.class)
                        .eq(Identify::getDept,dept.getDeptName())
                        .eq(Identify::getStatus,userDTO.getState());
            }

        }else { // 校级管理员 看所有  给校级多提供一个字段——院系名字
            if(StrUtil.isEmpty(userDTO.getDept()) || StrUtil.isBlank(userDTO.getDept())){
                if(StrUtil.isBlank(userDTO.getState()) || StrUtil.isEmpty(userDTO.getState())){
                    wrapper = Wrappers.lambdaQuery(Identify.class);
                }else {
                    wrapper = Wrappers.lambdaQuery(Identify.class)
                            .eq(Identify::getStatus,userDTO.getState());
                }

            }else {
                if(StrUtil.isBlank(userDTO.getState()) || StrUtil.isEmpty(userDTO.getState())){
                    wrapper = Wrappers.lambdaQuery(Identify.class)
                            .eq(Identify::getDept,userDTO.getDept());
                }else {
                    wrapper = Wrappers.lambdaQuery(Identify.class)
                            .eq(Identify::getDept,userDTO.getDept())
                            .eq(Identify::getStatus,userDTO.getState());
                }

            }
        }
        IPage<Identify> identifyIPage = baseMapper.selectPage(page, wrapper);
        List<Identify> records = identifyIPage.getRecords();
//        IPage<PaperVO> paperVOIPage = iBeanService.copyPageProperties(paperIPage, PaperVO.class);
        ArrayList<Identify> identifisList = new ArrayList<>();

        //对分页的设置
        int count = 1;
        int start = userDTO.getPageSize() * (userDTO.getPageNum()-1)+1;
        int end = userDTO.getPageNum() * userDTO.getPageSize();
        Collections.reverse(records);
        for (Identify record:records) {
            if (count >= start && count <= end){
                identifisList.add(this.getIdentify(record.getIdentifyID()));
//                paperList.add(this.getPaperVO(record.getPaperID()));
            }
            count += 1;
        }

//        Collections.reverse(identifisList);
        identifyIPage.setRecords(identifisList);
        identifyIPage.setTotal(records.size());

        return identifyIPage;
    }

//    @Override
//    public float[] getFigure(UserDTO userDTO) {
//        float[] result = new float[5];
//        User user = iUserService.getOne(Wrappers.lambdaQuery(User.class)
//                .eq(User::getName, userDTO.getName()));
//
//        LambdaQueryWrapper<Identify> wrapper = new LambdaQueryWrapper<>();
//        if(user.getRole().equals("19177623324")){//判断身份如果是普通用户的话
//            if(StrUtil.isBlank(userDTO.getState()) || StrUtil.isEmpty(userDTO.getState())){
//                wrapper = Wrappers.lambdaQuery(Identify.class)
//                        .eq(Identify::getEntered, userDTO.getName())
//                        .or().eq(Identify::getLeadAuthor, userDTO.getName())
//                        .or().eq(Identify::getCorrespondingAuthor,userDTO.getName())
//                        .or().like(Identify::getAllAuthor,userDTO.getName());
//            }else {
//                wrapper = Wrappers.lambdaQuery(Identify.class)
//                        .eq(Identify::getStatus,userDTO.getState())
//                        .eq(Identify::getEntered, userDTO.getName())
//                        .or().eq(Identify::getLeadAuthor, userDTO.getName())
//                        .or().eq(Identify::getCorrespondingAuthor,userDTO.getName())
//                        .or().like(Identify::getAllAuthor,userDTO.getName());
//            }
//
//        }else if (user.getRole().equals("19185212210")){ // 如果是院级管理员 给他看本院的
//            if(StrUtil.isBlank(userDTO.getState()) || StrUtil.isEmpty(userDTO.getState())){
//                Dept dept = iDeptService.getById(user.getDept());
//                wrapper = Wrappers.lambdaQuery(Identify.class)
//                        .eq(Identify::getDept,dept.getDeptName());
//            }else {
//                Dept dept = iDeptService.getById(user.getDept());
//                wrapper = Wrappers.lambdaQuery(Identify.class)
//                        .eq(Identify::getDept,dept.getDeptName())
//                        .eq(Identify::getStatus,userDTO.getState());
//            }
//
//        }else { // 校级管理员 看所有  给校级多提供一个字段——院系名字
//            if(StrUtil.isEmpty(userDTO.getDept()) || StrUtil.isBlank(userDTO.getDept())){
//                if(StrUtil.isBlank(userDTO.getState()) || StrUtil.isEmpty(userDTO.getState())){
//                    wrapper = Wrappers.lambdaQuery(Identify.class);
//                }else {
//                    wrapper = Wrappers.lambdaQuery(Identify.class)
//                            .eq(Identify::getStatus,userDTO.getState());
//                }
//
//            }else {
//                if(StrUtil.isBlank(userDTO.getState()) || StrUtil.isEmpty(userDTO.getState())){
//                    wrapper = Wrappers.lambdaQuery(Identify.class)
//                            .eq(Identify::getDept,userDTO.getDept());
//                }else {
//                    wrapper = Wrappers.lambdaQuery(Identify.class)
//                            .eq(Identify::getDept,userDTO.getDept())
//                            .eq(Identify::getStatus,userDTO.getState());
//                }
//
//            }
//        }
//        List<Identify> identifyList = baseMapper.selectList(wrapper);
//
//        for (Identify identify : identifyList) {
//            result[0] += identify.getScore();
//        }
//        return result;
//    }

    @Override
    public IPage<Identify> collegeUserGetIdentify(UserDTO userDTO) {
        User one = iUserService.getOne(Wrappers.lambdaQuery(User.class)
                .eq(User::getName, userDTO.getName()));
        if(Objects.isNull(one)){
            throw new BaseException("用户姓名有误!");
        }
        String dept = one.getDept();
        String deptName = iDeptService.getById(dept).getDeptName();
        String role = one.getRole();
        if(!role.equals("19185212210")){
            throw new BaseException("该用户权限不为院级审核员!");
        }
        IPage<Identify> page = PageUtil.getPage(userDTO.getPageNum(), userDTO.getPageSize());
        LambdaQueryWrapper<Identify> wrapper = Wrappers.lambdaQuery(Identify.class)
                .eq(Identify::getDept ,deptName)
                .and(wrapper1 -> wrapper1.eq(Identify::getStatus,"待院级审核"));

        IPage<Identify> identifyIPage = baseMapper.selectPage(page, wrapper);
        List<Identify> records = identifyIPage.getRecords();
//        IPage<PaperVO> paperVOIPage = iBeanService.copyPageProperties(paperIPage, PaperVO.class);
        ArrayList<Identify> identifyList = new ArrayList<>();

        //对分页的设置
        int count = 1;
        int start = userDTO.getPageSize() * (userDTO.getPageNum()-1)+1;
        int end = userDTO.getPageNum() * userDTO.getPageSize();
        Collections.reverse(records);
        for (Identify record:records) {
            if (count >= start && count <= end){
//                this.getPaper(record.getPaperID())
                identifyList.add(this.getIdentify(record.getIdentifyID()));
            }
            count += 1;
        }

//        Collections.reverse(identifyList);
        identifyIPage.setRecords(identifyList);
        identifyIPage.setTotal(records.size());

        return identifyIPage;
    }

    @Override
    public IPage<Identify> schoolUserGetIdentify(UserDTO userDTO) {
        User one = iUserService.getOne(Wrappers.lambdaQuery(User.class)
                .eq(User::getName, userDTO.getName()));
        if(Objects.isNull(one)){
            throw new BaseException("用户姓名有误!");
        }
        String dept = one.getDept();
        String deptName = iDeptService.getById(dept).getDeptName();
        String role = one.getRole();
        if(!role.equals("19190251173")){
            throw new BaseException("该用户权限不为校级审核员!");
        }
        IPage<Identify> page = PageUtil.getPage(userDTO.getPageNum(), userDTO.getPageSize());
        LambdaQueryWrapper<Identify> wrapper = Wrappers.lambdaQuery(Identify.class)
//                .eq(Paper::getDept,deptName)
                .and(wrapper1 -> wrapper1.eq(Identify::getStatus,"待校级审核"));

        IPage<Identify> identifyIPage = baseMapper.selectPage(page, wrapper);
        List<Identify> records = identifyIPage.getRecords();
//        IPage<PaperVO> paperVOIPage = iBeanService.copyPageProperties(paperIPage, PaperVO.class);
        ArrayList<Identify> identifyList = new ArrayList<>();

        //对分页的设置
        int count = 1;
        int start = userDTO.getPageSize() * (userDTO.getPageNum()-1)+1;
        int end = userDTO.getPageNum() * userDTO.getPageSize();
        Collections.reverse(records);
        for (Identify record:records) {
            if (count >= start && count <= end){
//                this.getPaper(record.getPaperID())
                identifyList.add(this.getIdentify(record.getIdentifyID()));
            }
            count += 1;
        }

//        Collections.reverse(identifyList);
        identifyIPage.setRecords(identifyList);
        identifyIPage.setTotal(records.size());

        return identifyIPage;
    }

    @Override
    public IPage<Identify> schoolUserGetIdentifyOver(UserDTO userDTO) {
        User one = iUserService.getOne(Wrappers.lambdaQuery(User.class)
                .eq(User::getName, userDTO.getName()));
        if(Objects.isNull(one)){
            throw new BaseException("用户姓名有误!");
        }
        String dept = one.getDept();
        String deptName = iDeptService.getById(dept).getDeptName();
        String role = one.getRole();
        if(!role.equals("19190251173")){
            throw new BaseException("该用户权限不为校级审核员!");
        }
        IPage<Identify> page = PageUtil.getPage(userDTO.getPageNum(), userDTO.getPageSize());
        LambdaQueryWrapper<Identify> wrapper = Wrappers.lambdaQuery(Identify.class)
//                .eq(Paper::getDept,deptName)
                .eq(Identify::getStatus,"审核通过")
                .or().eq(Identify::getStatus,"被校级退回");

        IPage<Identify> IdentifyIPage = baseMapper.selectPage(page, wrapper);
        List<Identify> records = IdentifyIPage.getRecords();
//        IPage<PaperVO> paperVOIPage = iBeanService.copyPageProperties(paperIPage, PaperVO.class);
        ArrayList<Identify> IdentifyList = new ArrayList<>();

        //对分页的设置
        int count = 1;
        int start = userDTO.getPageSize() * (userDTO.getPageNum()-1)+1;
        int end = userDTO.getPageNum() * userDTO.getPageSize();
        Collections.reverse(records);
        for (Identify record:records) {
            if (count >= start && count <= end){
//                this.getPaper(record.getPaperID())
                IdentifyList.add(this.getIdentify(record.getIdentifyID()));
            }
            count += 1;
        }

//        Collections.reverse(IdentifyList);
        IdentifyIPage.setRecords(IdentifyList);
        IdentifyIPage.setTotal(records.size());

        return IdentifyIPage;
    }

    @Override
    public IPage<Identify> collegeUserGetIdentifyOver(UserDTO userDTO) {
        User one = iUserService.getOne(Wrappers.lambdaQuery(User.class)
                .eq(User::getName, userDTO.getName()));
        if(Objects.isNull(one)){
            throw new BaseException("用户姓名有误!");
        }
        String dept = one.getDept();
        String deptName = iDeptService.getById(dept).getDeptName();
        String role = one.getRole();
        if(!role.equals("19185212210")){
            throw new BaseException("该用户权限不为院级审核员!");
        }
        IPage<Identify> page = PageUtil.getPage(userDTO.getPageNum(), userDTO.getPageSize());
        LambdaQueryWrapper<Identify> wrapper = Wrappers.lambdaQuery(Identify.class)
                .eq(Identify::getDept,deptName)
                .and(wrapper1 -> wrapper1.eq(Identify::getStatus,"审核通过")
                        .or().eq(Identify::getStatus,"被院级退回"));

        IPage<Identify> identifyIPage = baseMapper.selectPage(page, wrapper);
        List<Identify> records = identifyIPage.getRecords();
//        IPage<PaperVO> paperVOIPage = iBeanService.copyPageProperties(paperIPage, PaperVO.class);
        ArrayList<Identify> identifyList = new ArrayList<>();

        //对分页的设置
        int count = 1;
        int start = userDTO.getPageSize() * (userDTO.getPageNum()-1)+1;
        int end = userDTO.getPageNum() * userDTO.getPageSize();
        Collections.reverse(records);
        for (Identify record:records) {
            if (count >= start && count <= end){
//                this.getPaper(record.getPaperID())
                identifyList.add(this.getIdentify(record.getIdentifyID()));
            }
            count += 1;
        }

//        Collections.reverse(identifyList);
        identifyIPage.setRecords(identifyList);
        identifyIPage.setTotal(records.size());

        return identifyIPage;
    }
}
